package com.cci.kangdao.controller;

import com.cci.kangdao.service.SRTService;
import com.cci.kangdao.utilTool.ParameterTool;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @description:
 * @author: joe  APP系统请求CRM系统获取标准工时与失效代码
 * @company: CTY
 * @since: 2023/1/9 16:25
 * @version: V1.0
 **/
@Controller
public class SRTController {
    private Logger log = Logger.getLogger(this.getClass().getName());
    @Autowired
    private SRTService srtService;

    @RequestMapping("getSrtAndWfcFromSF.aspx")
    public void getSrtAndWfcFromSF(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> jsonmap) {
        try {
            log.error("getSrtAndWfcFromSF.aspx" + jsonmap != null ? jsonmap.toString() : "空map");
            //验证参数
            if (null == jsonmap) {
                ParameterTool.writeResponse(response, "参数为空");
                return;
            }
            String esn = MapUtils.getString(jsonmap, "esn");
            String smn = MapUtils.getString(jsonmap, "smn");
            if (StringUtils.isBlank(esn) && StringUtils.isBlank(smn)) {
                ParameterTool.writeResponse(response, -99, "esn或者smn为空");
                return;
            }
            String solutionList = MapUtils.getString(jsonmap, "solutionList");
            if (StringUtils.isBlank(solutionList)) {
                ParameterTool.writeResponse(response, -99, "solutionList为空");
                return;
            }
            jsonmap.put("response", response);
            srtService.getSrtAndWfcFromSF(jsonmap);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ParameterTool.writeErrorResponse(response);
        }
    }
}
